#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define LEFT  30000000
#define RIGHT  30000200


//筛选出质数
int main(){
	int i = 0 ;
	int mark = 0 ;
	pid_t pid = 0;
	for(i = LEFT; i < RIGHT;++i ){
		pid = fork();
		if(pid < 0)
			exit(1);
		else if (pid == 0){    // child
			mark = 1;
			for(j = 2;j < i/2; j++){
 				if(i %j == 0){
 					mark = 0;
					break;
				}
			}
			if (mark)
				printf("%d is a primer \n",i);
			exit(0);
		}
	}
	int st;
	for(i = LEFT; i <= RIGHT; i++){
		wait(&st);    //关心子进程结束的状态，不关心可以直接填NULL
	}
	exit(0);
}
